package com.game.number;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BoxPrinter {
	
	private int dimension=2;
	
	public BoxPrinter(int dimension){
		this.dimension=dimension;
	}
	
	public void print(Box2D box){
		switch(dimension){
			case 1:print1D(box);break;
			case 2:print2D(box);break;
			case 3:print3D(box);break;
		}
	}
	
	protected void print2D(Box2D box){
		List<Unit> units=box.getUnits();
		Collections.sort(units, new UnitComparator());
		String rowFlag="";
		for(Unit unit:units){
			
			String[] pos=unit.getSplitPosition();
			if(!rowFlag.equals(pos[1])){
				System.out.println("");
				rowFlag=pos[1];
			}
			System.out.print(unit.getValue()+"   ");
			
		}
		
	}
	
	protected void print1D(Box2D box){
		
	}
	
	protected void print3D(Box2D box){
		
	}
	
	public static void main(String[] args){
		
		ArrayList<Unit> units=new ArrayList<Unit>();
		Unit unit11=new Unit("1,1","1");
		Unit unit12=new Unit("1,2","2");
		Unit unit13=new Unit("1,3","3");
		Unit unit21=new Unit("2,1","4");
		Unit unit22=new Unit("2,2","5");
		Unit unit23=new Unit("2,3","6");
		Unit unit31=new Unit("3,1","7");
		Unit unit32=new Unit("3,2","8");
		Unit unit33=new Unit("3,3","9");
		units.add(unit11);
		units.add(unit12);
		units.add(unit13);
		units.add(unit21);
		units.add(unit22);
		units.add(unit23);
		units.add(unit31);
		units.add(unit32);
		units.add(unit33);
		Box2D box = new Box2D(units);
		BoxPrinter print=new BoxPrinter(2);
		print.print(box);
	}
}
